
import java.util.PriorityQueue;
import java.util.Stack;
// https://leetcode.cn/problems/minimum-absolute-difference-in-bst/description/
public class GetMinDiff {
    private static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        public TreeNode(int val)
        {
            this.val = val;
        }
    }
    class Solution {

        private TreeNode pre ;
        public int getMinimumDifference(TreeNode root) {
            Stack<TreeNode> stack = new Stack<>();
            int min = Integer.MAX_VALUE;

            while(!stack.isEmpty() || root != null)
            {
                while(root != null)
                {
                    stack.push(root);
                    root = root.left;
                }
                TreeNode node = stack.pop();
                System.out.print(node.val);
                if(pre != null)
                {
                    min = Math.min(min,Math.abs(node.val - pre.val));
                    if(min == 1)
                        return 1;
                }
                pre = node;
                root = node.right;
            }
            return min;


        }


    }
}
